% GAUTIER LE BIHAN - 2020
% Replication files for "Shocks vs Menu Costs: Patterns of Price Rigidity in an Estimated Multi-Sector Menu-Cost Model?" Review of Economics and Statistics
%
% This code produces  Figure 6 - Figure N

clear;
%close all;
tic
cd ..\..\Simulations_VC\MS_produits_CPlus


load ..\..\Simulations_VC\MS_produits_CPlus\stat_d
param=stat_d;
load ..\..\Estimation_param\MS_produits_CPlus\actual_moments_k
weight=actual_moments_k(:,12);
sum(weight)

secteur=actual_moments_k(:,1);
freq=actual_moments_k(:,2);
frac=actual_moments_k(:,3);
med=actual_moments_k(:,4);
inter=actual_moments_k(:,5);
kur=actual_moments_k(:,6);

p0=param(:,1);
muc=param(:,2);
sig_ea=param(:,3);
share_calvo=param(:,end-2);
av_muc=param(:,end);
v_dz=sqrt((2*sig_ea.^2)/(1+0.6946))

mu_tilda=muc.*(1-share_calvo);

stat_CalvoP=[ muc av_muc sig_ea share_calvo p0 mu_tilda v_dz];


load ..\..\Simulations_VC\MS_produits_MC\stat4
param=stat4;


secteur=actual_moments_k(:,1);

p0=param(:,1);
muc=param(:,2);
sig_ea=param(:,3);
rho_a=param(:,4);
sig_a=sig_ea./sqrt(1-rho_a.^2);
share_calvo=param(:,end-3);
muc=param(:,end-2);
av_muc=param(:,end-1);
v_dz=sqrt((2*sig_ea.^2)/(1+0.6946))
mu_tilda=muc.*(1-share_calvo);

stat_MC=[muc av_muc sig_ea share_calvo mu_tilda v_dz];

load ..\..\Simulations_VC\MS_produits_KR_CalvoPlus\stat4
param=stat4;


secteur=actual_moments_k(:,1);

p0=param(:,1);
muc=param(:,2);
sig_ea=param(:,3);
pz=param(:,4);
sig_a=sig_ea./sqrt(1-rho_a.^2);
share_calvo=param(:,end-3);
muc=param(:,end-2);
av_muc=param(:,end-1);
mu_tilda=muc.*(1-share_calvo);

v_dz=sqrt((2*pz.*sig_ea.^2)/(1+0.6946));
stat_KR_CalvoPlus=[muc av_muc sig_ea pz share_calvo p0 mu_tilda v_dz];

mean([mu_tilda v_dz])
load ..\..\Simulations_VC\MS_produits_KR_MC\stat4
param=stat4;
secteur=actual_moments_k(:,1);

p0=param(:,1);
muc=param(:,2);
sig_ea=param(:,3);
pz=param(:,4);
sig_a=sig_ea./sqrt(1-rho_a.^2);
share_calvo=param(:,end-3);
muc=param(:,end-2);
av_muc=param(:,end-1);
v_dz=sqrt((2*pz.*sig_ea.^2)/(1+0.6946))
mu_tilda=muc.*(1-share_calvo);


stat_KR_MC=[muc av_muc sig_ea pz share_calvo p0 mu_tilda v_dz];

z=(stat_KR_MC((freq(:,1)<0.2) ,end));
mean([mu_tilda v_dz])
mean(z)
zb=z-mean(z);
z1=stat_CalvoP((freq(:,1)<0.2),end);
mean(z1)
z1b=z1-mean(z1);
m=(stat_KR_MC((freq(:,1)<0.2) ,end-1));
mb=m-mean(m);
m1=stat_CalvoP((freq(:,1)<0.2) ,end-1);
m1b=m1-mean(m1);
freqs=freq((freq(:,1)<0.2) ,1);

max_z=0.08
max_zb=0.05
figure(2);
subplot(2,1,1)
scatter(z1( z1b(:,1)<max_zb & zb(:,1)<max_zb,1),z( z1b(:,1)<max_zb & zb(:,1)<max_zb,1))
lsline
xlabel('CalvoPlus') % x-axis label
ylabel('MC Lepto') % y-axis label
title('$\tilde{\sigma}$','interpreter','latex')
subplot(2,1,2)

scatter(m1( m1b(:,1)<max_z & mb(:,1)<max_z,1),m( m1b(:,1)<max_z & mb(:,1)<max_z,1))
lsline
xlabel('CalvoPlus') % x-axis label
ylabel('MC Lepto') % y-axis label
title('$\tilde{\mu}$','interpreter','latex')

figure(4);
subplot(2,3,1)
m=(stat_MC((freq(:,1)<0.2) ,end-1));
mb=m-mean(m);
m1=stat_CalvoP((freq(:,1)<0.2) ,end-1);
m1b=m1-mean(m1);
scatter(m1( m1b(:,1)<max_z & mb(:,1)<max_z,1),m( m1b(:,1)<max_z & mb(:,1)<max_z,1))
lsline
xlabel('CalvoPlus') % x-axis label
ylabel('MC') % y-axis label
title('$\tilde{\mu}$','interpreter','latex')
subplot(2,3,4)
z=(stat_MC((freq(:,1)<0.2) ,end));
zb=z-mean(z);
z1=stat_CalvoP((freq(:,1)<0.2),end);
z1b=z1-mean(z1);
scatter(z1( z1b(:,1)<max_zb & zb(:,1)<max_zb,1),z( z1b(:,1)<max_zb & zb(:,1)<max_zb,1))
lsline
xlabel('CalvoPlus') % x-axis label
ylabel('MC') % y-axis label
title('$\tilde{\sigma}$','interpreter','latex')

subplot(2,3,5)
z=(stat_KR_MC((freq(:,1)<0.2) ,end));
zb=z-mean(z);
z1=stat_CalvoP((freq(:,1)<0.2),end);
z1b=z1-mean(z1);
scatter(z1( z1b(:,1)<max_zb & zb(:,1)<max_zb,1),z( z1b(:,1)<max_zb & zb(:,1)<max_zb,1))
lsline
xlabel('CalvoPlus') % x-axis label
ylabel('MC Lepto') % y-axis label
title('$\tilde{\sigma}$','interpreter','latex')
subplot(2,3,2)
m=(stat_KR_MC((freq(:,1)<0.2) ,end-1));
mb=m-mean(m);
m1=stat_CalvoP((freq(:,1)<0.2) ,end-1);
m1b=m1-mean(m1);
scatter(m1( m1b(:,1)<max_z & mb(:,1)<max_z,1),m( m1b(:,1)<max_z & mb(:,1)<max_z,1))
lsline
xlabel('CalvoPlus') % x-axis label
ylabel('MC Lepto') % y-axis label
title('$\tilde{\mu}$','interpreter','latex')
subplot(2,3,6)
z=(stat_KR_CalvoPlus((freq(:,1)<0.2) ,end));
zb=z-mean(z);
z1=stat_CalvoP((freq(:,1)<0.2),end);
z1b=z1-mean(z1);
scatter(z1( z1b(:,1)<max_zb & zb(:,1)<max_zb,1),z( z1b(:,1)<max_zb & zb(:,1)<max_zb,1))
lsline
xlabel('CalvoPlus') % x-axis label
ylabel('CalvoPlus Lepto') % y-axis label
title('$\tilde{\sigma}$','interpreter','latex')
subplot(2,3,3)
m=(stat_KR_CalvoPlus((freq(:,1)<0.2) ,end-1));
mb=m-mean(m);
m1=stat_CalvoP((freq(:,1)<0.2) ,end-1);
m1b=m1-mean(m1);
scatter(m1( m1b(:,1)<max_z & mb(:,1)<max_z,1),m( m1b(:,1)<max_z & mb(:,1)<max_z,1))
lsline
xlabel('CalvoPlus') % x-axis label
ylabel('CalvoPlus Lepto') % y-axis label
title('$\tilde{\mu}$','interpreter','latex')
print('..\..\..\figures\compar_param.pdf','-dpdf','-fillpage')
print('..\..\..\figures\compar_param','-depsc')



figure(1);
subplot(2,5,1)
scatter(z1b( z1b(:,1)<max_zb & zb(:,1)<max_zb,1),freqs( z1b(:,1)<max_zb & zb(:,1)<max_zb,1))
%lsline
hold on;
scatter(zb( z1b(:,1)<max_zb & zb(:,1)<max_zb,1),freqs(z1b(:,1)<max_zb & zb(:,1)<max_zb,1))
%lsline
hold off;
xlabel('\sigma') % x-axis label
ylabel('Freq.') % y-axis label


subplot(2,5,6)
scatter(m1b(m1b(:,1)<max_z & mb(:,1)<max_z,1),freqs(m1b(:,1)<max_z & mb(:,1)<max_z,1))
%lsline
hold on;
scatter(mb(m1b(:,1)<max_z & mb(:,1)<max_z,1),freqs( m1b(:,1)<max_z & mb(:,1)<max_z,1))
%lsline
hold off;
xlabel('\mu') % x-axis label
ylabel('Freq.') % y-axis label

subplot(2,5,2)
meds=med((med(:,1)<0.15) ,1);
m=(stat_KR_MC((med(:,1)<0.15) ,end-1));
mb=m-mean(m);
m1=stat_CalvoP((med(:,1)<0.15) ,end-1);
m1b=m1-mean(m1);


z=(stat_KR_MC((med(:,1)<0.15) ,end));
zb=z-mean(z);
z1=stat_CalvoP((med(:,1)<0.15),end);
z1b=z1-mean(z1);

scatter(z1b( z1b(:,1)<max_zb & zb(:,1)<max_zb,1),meds( z1b(:,1)<max_zb & zb(:,1)<max_zb,1))
%lsline
hold on;
scatter(zb( z1b(:,1)<max_zb & zb(:,1)<max_zb,1),meds(z1b(:,1)<max_zb & zb(:,1)<max_zb,1))
%lsline
hold off;

xlabel('\sigma') % x-axis label
ylabel('Median') % y-axis label

subplot(2,5,7)
scatter(m1b(m1b(:,1)<max_z & mb(:,1)<max_z,1),meds(m1b(:,1)<max_z & mb(:,1)<max_z,1))
%lsline
hold on;
scatter(mb(m1b(:,1)<max_z & mb(:,1)<max_z,1),meds( m1b(:,1)<max_z & mb(:,1)<max_z,1))
%lsline
hold off;

xlabel('\mu') % x-axis label
ylabel('Median') % y-axis label
subplot(2,5,3)
fracs=frac(frac>0.3 ,1);
m=(stat_KR_MC(frac>0.3 ,end-1));
mb=m-mean(m);
m1=stat_CalvoP(frac>0.3 ,end-1);
m1b=m1-mean(m1);

z=(stat_KR_MC((frac>0.3) ,end));
zb=z-mean(z);
z1=stat_CalvoP((frac>0.3),end);
z1b=z1-mean(z1);


scatter(z1b( z1b(:,1)<max_zb & zb(:,1)<max_zb,1),fracs( z1b(:,1)<max_zb & zb(:,1)<max_zb,1))
%lsline
hold on;
scatter(zb( z1b(:,1)<max_zb & zb(:,1)<max_zb,1),fracs(z1b(:,1)<max_zb & zb(:,1)<max_zb,1))
%lsline
hold off;

xlabel('\sigma') % x-axis label
ylabel('Frac up') % y-axis label
subplot(2,5,8)
scatter(m1b(m1b(:,1)<max_z & mb(:,1)<max_z,1),fracs(m1b(:,1)<max_z & mb(:,1)<max_z,1))
%lsline
hold on;
scatter(mb(m1b(:,1)<max_z & mb(:,1)<max_z,1),fracs( m1b(:,1)<max_z & mb(:,1)<max_z,1))
%lsline
hold off;
xlabel('\mu') % x-axis label
ylabel('Frac up') % y-axis label



subplot(2,5,4)
inters=inter(inter<0.25 ,1);
m=(stat_KR_MC(inter<0.25 ,end-1));
mb=m-mean(m);
m1=stat_CalvoP(inter<0.25 ,end-1);
m1b=m1-mean(m1);

z=(stat_KR_MC(inter<0.25 ,end));
zb=z-mean(z);
z1=stat_CalvoP(inter<0.25,end);
z1b=z1-mean(z1);


scatter(z1b( z1b(:,1)<max_zb & zb(:,1)<max_zb,1),inters( z1b(:,1)<max_zb & zb(:,1)<max_zb,1))
%lsline
hold on;
scatter(zb( z1b(:,1)<max_zb & zb(:,1)<max_zb,1),inters(z1b(:,1)<max_zb & zb(:,1)<max_zb,1))
%lsline
hold off;

xlabel('\sigma') % x-axis label
ylabel('Interq') % y-axis label

subplot(2,5,9)
scatter(m1b(m1b(:,1)<max_z & mb(:,1)<max_z,1),inters(m1b(:,1)<max_z & mb(:,1)<max_z,1))
%lsline
hold on;
scatter(mb(m1b(:,1)<max_z & mb(:,1)<max_z,1),inters( m1b(:,1)<max_z & mb(:,1)<max_z,1))
%lsline
hold off;
xlabel('\mu') % x-axis label
ylabel('Interq') % y-axis label


subplot(2,5,5)
kurs=kur(kur<15 ,1);
m=(stat_KR_MC(kur<15 ,end-1));
mb=m-mean(m);
m1=stat_CalvoP(kur<15 ,end-1);
m1b=m1-mean(m1);

z=(stat_KR_MC(kur<15 ,end));
zb=z-mean(z);
z1=stat_CalvoP(kur<15,end);
z1b=z1-mean(z1);


% scatter(z1b( z1b(:,1)<0.1 & zb(:,1)<max_zb,1),kurs( z1b(:,1)<max_zb & zb(:,1)<max_zb,1))
%lsline
hold on;
% scatter(zb( z1b(:,1)<0.1 & zb(:,1)<max_zb,1),kurs(z1b(:,1)<max_zb & zb(:,1)<max_zb,1))
%lsline
hold off;

xlabel('\sigma') % x-axis label
ylabel('Kur') % y-axis label

subplot(2,5,10)
scatter(m1b(m1b(:,1)<max_z & mb(:,1)<max_z,1),kurs(m1b(:,1)<max_z & mb(:,1)<max_z,1))
%lsline
hold on;
scatter(mb(m1b(:,1)<max_z & mb(:,1)<max_z,1),kurs( m1b(:,1)<max_z & mb(:,1)<max_z,1))
%lsline
hold off;
xlabel('\mu') % x-axis label
ylabel('Kur') % y-axis label
 print('..\..\..\figures\figure8.pdf','-dpdf', '-fillpage')
 print('..\..\..\figures\figure8','-depsc')
 
 
 
 figure(3);
 
 z=(stat_KR_MC((freq(:,1)<0.2) ,end));
zb=z-mean(z);
z1=stat_CalvoP((freq(:,1)<0.2),end);
z1b=z1-mean(z1);

m=(stat_KR_MC((freq(:,1)<0.2) ,end-1));
mb=m-mean(m);
m1=stat_CalvoP((freq(:,1)<0.2) ,end-1);
m1b=m1-mean(m1);
freqs=freq((freq(:,1)<0.2) ,1);
 
 


subplot(2,2,1)
scatter(m1b(m1b(:,1)<max_z & mb(:,1)<max_z,1),freqs(m1b(:,1)<max_z & mb(:,1)<max_z,1),'o','k')
axis([-0.05 0.05 0 0.2 ])

hold on;
scatter(mb(m1b(:,1)<max_z & mb(:,1)<max_z,1),freqs( m1b(:,1)<max_z & mb(:,1)<max_z,1),'^','MarkerEdgeColor' ,[0.5 0.5 0.5],'MarkerFaceColor',[0.5 0.5 0.5])
%lsline
hold off;
xlabel('$\tilde{\mu}$','interpreter','latex') % x-axis label
ylabel('Freq.') % y-axis label

subplot(2,2,3)
scatter(z1b( z1b(:,1)<max_zb & zb(:,1)<max_zb,1),freqs( z1b(:,1)<max_zb & zb(:,1)<max_zb,1),'o','k')
axis([-0.05 0.05 0 0.2 ])

hold on;
scatter(zb( z1b(:,1)<max_zb & zb(:,1)<max_zb,1),freqs(z1b(:,1)<max_zb & zb(:,1)<max_zb,1),'^','MarkerEdgeColor' ,[0.5 0.5 0.5],'MarkerFaceColor',[0.5 0.5 0.5])
%lsline
hold off;
xlabel('$\tilde{\sigma}$','interpreter','latex') % x-axis label
ylabel('Freq.') % y-axis label


subplot(2,2,4)
 meds=med((med(:,1)<0.15) ,1);
m=(stat_KR_MC((med(:,1)<0.15) ,end-1));
mb=m-mean(m);
m1=stat_CalvoP((med(:,1)<0.15) ,end-1);
m1b=m1-mean(m1);


z=(stat_KR_MC((med(:,1)<0.15) ,end));
zb=z-mean(z);
z1=stat_CalvoP((med(:,1)<0.15),end);
z1b=z1-mean(z1);
scatter(z1b( z1b(:,1)<max_zb & zb(:,1)<max_zb,1),meds( z1b(:,1)<max_zb & zb(:,1)<max_zb,1),'o','k')
axis([-0.05 0.05 0 0.125 ])

hold on;
scatter(zb( z1b(:,1)<max_zb & zb(:,1)<max_zb,1),meds(z1b(:,1)<max_zb & zb(:,1)<max_zb,1),'^','MarkerEdgeColor' ,[0.5 0.5 0.5],'MarkerFaceColor',[0.5 0.5 0.5])
%lsline
hold off;

xlabel('$\tilde{\sigma}$','interpreter','latex') % x-axis label
ylabel('Median') % y-axis label

subplot(2,2,2)
scatter(m1b(m1b(:,1)<max_z & mb(:,1)<max_z,1),meds(m1b(:,1)<max_z & mb(:,1)<max_z,1),'k')
axis([-0.05 0.05 0 0.125 ])

hold on;
scatter(mb(m1b(:,1)<max_z & mb(:,1)<max_z,1),meds( m1b(:,1)<max_z & mb(:,1)<max_z,1),'^','MarkerEdgeColor' ,[0.5 0.5 0.5],'MarkerFaceColor',[0.5 0.5 0.5])
%lsline
hold off;

xlabel('$\tilde{\mu}$','interpreter','latex') % x-axis label
ylabel('Median') % y-axis label


 print('..\..\..\figures\figure8b.pdf','-dpdf', '-fillpage')
 print('..\..\..\figures\figure8b','-depsc')

 
 